package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.common.entity.UserInfo;
import com.nineclock.common.utils.CurrentUserHolder;
import com.nineclock.system.dto.SysAdminDTO;
import com.nineclock.system.dto.SysChangeAdminDTO;
import com.nineclock.system.dto.SysCompanyDTO;
import com.nineclock.system.dto.SysUserDTO;
import com.nineclock.system.pojo.SysCompany;
import com.nineclock.system.service.CompanyService;
import com.nineclock.system.vo.SysCompanyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * @author yangchao
 * @create 2022-01-13 8:56
 **/
@RestController
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    CompanyService companyService;

    /**
     * 查询当前用户所在的企业信息
     * @return
     */
    @GetMapping
    public Result<SysCompanyVO> findCompany(){
        SysCompanyVO company = companyService.findCompany();
        return Result.success(company);
    }

    /**
     * 上传图片到阿里云OSS服务器
     * @return
     */
    @PostMapping("/uploadOSS")
    public Result uploadCompanyImg(@RequestParam("file")MultipartFile multipartFile){

        //返回上传的图片路径
        String uploadImgUrl = companyService.uploadCompanyImg(multipartFile);

        return Result.success(uploadImgUrl);
    }

    /**
     * 修改当前企业信息
     * @param sysCompanyDTO
     * @return
     */
    @PutMapping
    public Result updateCompany(@RequestBody SysCompanyDTO sysCompanyDTO){

        companyService.updateCompany(sysCompanyDTO);
        return Result.success();
    }

    /**
     * 获取企业当前主管理员
     * @return
     */
    @GetMapping("/getCurrentAdmin")
    public Result getCurrentAdmin(){

        SysAdminDTO currentAdmin = companyService.getCurrentAdmin();

        return Result.success(currentAdmin);
    }

    /**
     * 更改系统管理员
     * @return
     */
    @PostMapping("/config/admin")
    public Result changeSystemAdmin(@RequestBody SysChangeAdminDTO sysChangeAdminDTO){

        companyService.changeSystemAdmin(sysChangeAdminDTO);

        return Result.successMessage("更换系统管理员成功");
    }

}
